package Function;

import VWorldGameStudio.events.SayEvent;
import VWorldGameStudio.events.ShopEvent;
import com.google.gson.Gson;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import utils.FCDataSingles;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;

//TODO 可以一键生成商店事件，和商店对话事件以及商人Npc,包括酒吧卖酒的了，赏金店
public class BuildFCShopEventByExcelMain {

    private static final String ITEM_FILE = "./重装机兵V-数据-怪物.xls";
    private Gson gson = new Gson();
    Sheet sheet;

    public static void main(String[] args) {
        BuildFCShopEventByExcelMain main = new BuildFCShopEventByExcelMain();
        main.init();
    }

    private void init() {
        try {
            int ids = 1;
            FCItemLibrary itemLibrary = new FCItemLibrary();
            itemLibrary.loadItemData();
            File file = new File(ITEM_FILE);
            // 创建输入流，读取Excel
            InputStream is = new FileInputStream(file.getAbsolutePath());
            // jxl提供的Workbook类
            Workbook wb = Workbook.getWorkbook(is);
            sheet = wb.getSheet(2);
            FCCharacterLibrary fcCharacterLibrary = new FCCharacterLibrary();
            int npcId = 1000;
            for (int i = 1; i < sheet.getRows(); i++) {
                Cell[] cells = sheet.getRow(i);
                if (cells != null && cells.length > 4) {
                    if (cells[3] == null || cells[3].getContents().isEmpty()) {
                        continue;
                    }
                    String name = cells[3].getContents().trim();
                    ShopEvent shopEvent = new ShopEvent("shop", name);
                    shopEvent.setIsvending(false);
                    shopEvent.setType2("def");
                    for (int n = 4; n < cells.length; n++) {
                        Cell cell_1 = cells[n];
                        if (cell_1 == null || cell_1.getContents().isEmpty()) {
                            continue;
                        }
                        String content = cell_1.getContents().trim();
                        shopEvent.getItemid().add(content);
                        shopEvent.getItemprice().add(1);

                        //减去已有的物品
                        itemLibrary.getItemName().remove(content);
                    }
                    //创建对话事件
                    String say = "hummanWuQiShopSay";
                    if(shopEvent.getName().contains("H-WuQi")){

                    }else if(shopEvent.getName().contains("H-Tool")){
                        say = "hummanToolShopSay";
                    }else if(shopEvent.getName().contains("T-WuQi")){
                        say = "tankWuQiShopSay";
                    }else if(shopEvent.getName().contains("T-Tool")){
                        say = "tankToolShopSay";
                    }else if(shopEvent.getName().contains("T-Pao")){
                        say = "tankPaoShopSay";
                    }
                    say = say +"\u003coption1 open\u003d\u0027"+shopEvent.getName()+"\u0027\u003e\u003coption2 open\u003d\u0027buyOutShopEvent\u0027\u003e";
                    if(shopEvent.getName().contains("BAR")){
                        say= "barServer-1-1"+"\u003coption1 open\u003d\u0027"+shopEvent.getName()+"\u0027\u003e\u003coption2 id\u003d\u0027barServer-1-2\u0027\u003e";
                        shopEvent.setType2("BAR");
                    }else if(shopEvent.getName().contains("Wanted")){
                        say= "wantedShop-1-1"+"\u003coption1 open\u003d\u0027"+shopEvent.getName()+"\u0027\u003e\u003coption2 id\u003d\u0027wantedShop-2-2\u0027\u003e";
                        shopEvent.setType2("RewardShop");
                    }
                    FCDataSingles.getWriter().writeEventData(shopEvent);
                    SayEvent sayEvent = new SayEvent("say", shopEvent.getName()+"-Say");
                    sayEvent.addSayText(say);
                    FCDataSingles.getWriter().writeEventData(sayEvent);
                    //创建NPC
                    String pngName = cells[1].getContents().trim();
                    String actionName =  cells[2].getContents().trim();
                    pngName = "./material/png/character/"+pngName;
                    fcCharacterLibrary.registerCharater(false, npcId++, shopEvent.getName()+"-Npc","npc",actionName, sayEvent.getName(),pngName);
                }
            }

            System.out.println("打印还有那些物品未上架商品使用的");
            for(String name: itemLibrary.getItemName()){
                System.out.println("=============="+name);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
